var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        text_id: "",
        appointmentLang: {},
        showMember: !1,
        show: !1,
        applyModel: {
            description: "",
            member_u_id: "",
            name: "",
            project_ids: [],
            thumb: "",
            worker_content: [],
            worker_id: "",
            leader_uid: "",
            leader_commission: ""
        },
        uploadUrl: "upload.uploadPic",
        usetName: "",
        swlist: []
    },
    onLoad: function(t) {
        t.worker_id && this.setData({
            worker_id: t.worker_id
        }), t.store_id && this.setData({
            store_id: t.store_id
        }), this.data.worker_id && this.GeteditTechnician();
        try {
            var e = wx.getStorageSync("yz_basic_info");
            e && (this.setData({
                appointmentLang: e.lang.appointment
            }), t.worker_id ? wx.setNavigationBarTitle({
                title: "编辑".concat(e.lang.appointment.worker)
            }) : wx.setNavigationBarTitle({
                title: "添加".concat(e.lang.appointment.worker)
            }));
        } catch (t) {
            console.log(t);
        }
    },
    removeImg: function(t) {
        console.log(this.data.applyModel, t);
        var e = this.data.applyModel.worker_content, a = t.currentTarget.dataset.ind;
        e.splice(a, 1), this.setData({
            "applyModel.worker_content": e
        });
    },
    description_inp: function(t) {
        console.log(t), this.setData({
            "applyModel.description": t.detail.value
        });
    },
    chooseMember: function(t) {
        "up" == t.currentTarget.dataset.up ? this.setData({
            leader_uid: "".concat(t.currentTarget.dataset.item.nickname, "(id:").concat(t.currentTarget.dataset.item.uid, ")"),
            "applyModel.leader_uid": t.currentTarget.dataset.item.uid,
            showUPMember: !1
        }) : this.setData({
            text_id: "".concat(t.currentTarget.dataset.item.nickname, "(id:").concat(t.currentTarget.dataset.item.uid, ")"),
            "applyModel.member_u_id": t.currentTarget.dataset.item.uid,
            showMember: !1
        });
    },
    getMember: function(t) {
        var a = t.currentTarget.dataset.up;
        if ("money" !== a) {
            var o = this, i = e.getNetAddresss("plugin.appointment.frontend.member.query-list");
            e._getNetWork({
                url: i,
                data: {
                    keyword: t.detail.value
                },
                success: function(t) {
                    var e = t.data;
                    if (1 == e.result) {
                        var i = e.data;
                        o.setData({
                            member: e.data
                        }), i.length > 0 && ("up" === a ? o.setData({
                            showUPMember: !0
                        }) : o.setData({
                            showMember: !0
                        }));
                    } else "up" === a ? o.setData({
                        showUPMember: !0
                    }) : o.setData({
                        showMember: !0
                    }), o.setData({
                        member: []
                    });
                }
            }), console.log({});
        } else this.setData({
            "applyModel.leader_commission": t.detail.value
        });
    },
    getMember_name: function(t) {
        var e = t.detail.value;
        this.setData({
            "applyModel.name": e
        });
    },
    showUPMemberTap: function(t) {
        console.log(t);
    },
    showUPMemberTap_name: function(t) {},
    onRead: function() {
        var t = this, a = e.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                var o = e.tempFilePaths[0];
                wx.uploadFile({
                    url: a,
                    filePath: o,
                    name: "file",
                    success: function(e) {
                        var a = JSON.parse(e.data);
                        1 == a.result ? (console.log(a.data), t.setData({
                            "applyModel.thumb": a.data.img_url
                        })) : wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_2: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                console.log(e.tempFilePaths), t.unload({
                    tempFilePaths: e.tempFilePaths
                }, "1");
            }
        });
    },
    unload: function(t, a) {
        console.log(a);
        var o = e.getNetAddresss(this.data.uploadUrl), i = this, s = t.i ? t.i : 0, n = t.success ? t.success : 0, r = t.fail ? t.fail : 0;
        wx.uploadFile({
            url: o,
            filePath: t.tempFilePaths[s],
            name: "file",
            formData: null,
            success: function(t) {
                var e = JSON.parse(t.data);
                console.log(e.data.img_url), "1" == a ? (i.data.swlist.push(e.data.img_url), i.setData({
                    "applyModel.worker_content": i.data.swlist
                })) : 2 == a && (i.data.swlis.push(e.data.img_url), i.setData({
                    "applyModel.worker_content": i.data.swlis
                })), console.log(i.data.applyModel);
            },
            fail: function(t) {
                r++;
            },
            complete: function(e) {
                ++s == t.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + n + " 失败：" + r)) : (t.i = s, 
                t.success = n, t.fail = r, i.unload(t, a));
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    addTechnician: function(t) {
        console.log(this.data.applyModel);
        var a = this.data.applyModel;
        if (e._isTextEmpty(a.member_u_id) && e._isTextEmpty(a.leader_uid)) wx.showToast({
            title: "".concat(this.data.appointmentLang.worker, "会员ID/昵称不能为空"),
            duration: 1e3,
            icon: "none"
        }); else if (e._isTextEmpty(a.name)) wx.showToast({
            title: "".concat(this.data.appointmentLang.worker, "姓名不能为空"),
            duration: 1e3,
            icon: "none"
        }); else if (a.project_ids.length <= 0) wx.showToast({
            title: "关联".concat(this.data.appointmentLang.project, "不能为空"),
            duration: 1e3,
            icon: "none"
        }); else if (a.worker_content.length <= 0) wx.showToast({
            title: "".concat(this.data.appointmentLang.worker, "介绍不能为空"),
            duration: 1e3,
            icon: "none"
        }); else if (e._isTextEmpty(a.thumb)) wx.showToast({
            title: "".concat(this.data.appointmentLang.worker, "头像不能为空"),
            duration: 1e3,
            icon: "none"
        }); else {
            Array.isArray(this.data.applyModel.project_ids) && this.setData({
                "applyModel.project_ids": String(this.data.applyModel.project_ids)
            }), this.setData({
                "applyModel.store_id": this.data.store_id
            });
            var o = e.getNetAddresss("plugin.appointment.frontend.worker.add-worker");
            e._postNetWork({
                url: o,
                data: this.data.applyModel,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (console.log(e), wx.showToast({
                        title: e.msg,
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    })) : (wx.showToast({
                        title: e.msg,
                        icon: "none"
                    }), console.log(e.msg));
                }
            });
        }
    },
    popupComfirm: function(t) {
        console.log(this.data.applyModel.project_ids), this.setData({
            show: !1,
            "applyModel.project_ids": this.data.applyModel.project_ids
        });
    },
    allSelectHandle: function(t) {
        var e = t.detail;
        e = e.filter(function(t) {
            return "" !== t;
        }), this.setData({
            "applyModel.project_ids": e
        });
    },
    showCloseBtn: function(t) {
        this.setData({
            show: !1
        });
    },
    editTechnician: function() {
        if (this.data.showMember || this.data.showUPMember) wx.showToast({
            title: "请选择用户",
            duration: 1e3,
            icon: "none"
        }); else if (e._isTextEmpty(this.data.applyModel.project_ids)) wx.showToast({
            title: "请选择关联".concat(this.data.appointmentLang.project),
            duration: 1e3,
            icon: "none"
        }); else if (this.data.applyModel.name) {
            this.setData({
                "applyModel.worker_id": this.data.worker_id
            }), Array.isArray(this.data.applyModel.project_ids) && this.setData({
                "applyModel.project_ids": String(this.data.applyModel.project_ids)
            });
            var t = e.getNetAddresss("plugin.appointment.frontend.worker.edit-worker");
            e._postNetWork({
                url: t,
                data: this.data.applyModel,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (console.log(e), wx.showToast({
                        title: e.msg,
                        icon: "none",
                        duration: 1e3,
                        success: function(t) {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1e3);
                        }
                    })) : (wx.showToast({
                        title: e.msg,
                        icon: "none"
                    }), console.log(e.msg));
                }
            });
        } else wx.showToast({
            title: "".concat(this.data.appointmentLang.worker, "姓名不能为空"),
            duration: 1e3,
            icon: "none"
        });
    },
    getProject: function() {
        "string" == typeof this.data.applyModel.project_ids && this.setData({
            "applyModel.project_ids": this.data.applyModel.project_ids.split(",")
        });
        var t = this, a = e.getNetAddresss("plugin.appointment.frontend.project.get-list-by-store-id");
        e._postNetWork({
            url: a,
            data: {
                store_id: this.options.store_id
            },
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    projects: a.data,
                    show: !0
                }) : (wx.showToast({
                    title: a.msg,
                    icon: "none"
                }), console.log(a.msg));
            }
        });
    },
    GeteditTechnician: function() {
        var t = this, a = e.getNetAddresss("plugin.appointment.frontend.worker.edit-show-info");
        e._postNetWork({
            url: a,
            data: {
                worker_id: this.data.worker_id
            },
            success: function(e) {
                var a = e.data;
                if (1 == a.result) {
                    console.log(a);
                    var o = a.data;
                    !o.project_ids && applyModel.project_ids.length <= 0 && t.setData({
                        "applyModel.project_ids": t.applyModel.project_ids.push(o.project_ids)
                    }), t.setData({
                        Data: a.data,
                        text_id: o.member_nickname + "  (id:" + o.member_u_id + ")",
                        leader_uid: o.leader_nickname + "  (id:" + o.leader_uid + ")",
                        "applyModel.leader_commission": o.leader_commission,
                        "applyModel.name": o.name,
                        "applyModel.thumb": o.thumb,
                        "applyModel.description": o.description,
                        "applyModel.project_ids": o.project_ids.split(","),
                        "applyModel.member_u_id": o.member_u_id
                    });
                } else wx.showToast({
                    title: a.msg,
                    icon: "none"
                }), console.log(a.msg);
            }
        });
    },
    onBlurPop: function(e) {
        var a, o = e.target.dataset || e.currentTarget.dataset, i = o.t, s = o.v;
        0 == this.data.member.length && this.setData((t(a = {}, i, !1), t(a, s, ""), a));
    },
    toEditTime: function() {
        wx.navigateTo({
            url: "/packageE/appointment/technician/work_day/TechnicianTime/TechnicianTime?worker_id=" + this.data.worker_id + "&muid=" + this.data.Data.member_u_id
        });
    }
});